<?php
	$uname="";$passwd="";
	if(isset($_GET['uname']))
		$uname=$_GET['uname'];
	if(isset($_GET['passwd']))
		$passwd=$_GET['passwd'];

	if(strlen($passwd) == 0) {
		echo "Password is empty";
		exit ;
	}
	if(strlen($uname) == 0) {
		echo "User is empty";
		exit ;
	}

	$users = json_decode(file_get_contents('passwd.json'),true);
    if(!isset($users[$uname])) {
		echo "$uname is a new user.<BR>";
		$users[$uname] = $passwd;
		file_put_contents("passwd.json",json_encode($users));
		echo "$uname is registerd<BR>";
		mkdir("users/".md5($uname));
		touch("users/".md5($uname)."/settings.json");
		#echo "<script lang=javascript> document.location.href=(\"topframe.php?local=$uname\");</script>";
		echo "<script lang=javascript> document.location.href=(\"init_settings.php?uid=$uname\");</script>";
		
	}
	else {
		echo "$uname is  set<BR>";
		
		
		if($users[$uname] != $passwd)
			echo "password is wrong  <BR>";
		else {
			echo "password is correct<BR>";
			#echo "<script lang=javascript> document.location.href=(\"topframe.php?local=$uname\");</script>";
			echo "<script lang=javascript> document.location.href=(\"init_settings.php?uid=$uname\");</script>";

			
		}
	}

	
?>
